import { CanActivate } from "@angular/router";
import { Injectable } from "@angular/core";
import { userService } from "../../user/share/user.service";
import { ActivatedRoute, Router, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot } from '@angular/router';
@Injectable()
export class userActiveInter implements CanActivate {
        active: boolean = false;

        constructor(private UserService: userService, public router: Router, public activatedRoute: ActivatedRoute) {

        }
        canActivate() {

                //判断逻辑
                //返回true则通过  返回false则不通过
                //也可以通过订阅的方式
                let activatedRouteSnapshot: ActivatedRouteSnapshot = this.activatedRoute.snapshot;
                let routerState: RouterState = this.router.routerState;
                let routerStateSnapshot: RouterStateSnapshot = routerState.snapshot;
                console.log("！！！！！！！！！！！！！！！！！！！");
                console.log(this.UserService.isLogin);
                if (this.UserService.isLogin) {

                        this.active = true;
                } else {
                        console.log("当前路由状态：");
                        console.log(this.router.url);
                        this.router.navigateByUrl("user/login");
                        // alert("请先登录");
                }
                return this.active;
        }

}